function [A,v,b,v2] = generAvb(nn,tau1,tau2)
%generate A and random initial state
h = 1/(nn+1);
eta1 = tau1/2/(nn+1);
eta2 = tau2/2/(nn+1);
e = ones(nn,1);
C1 = spdiags([e+eta1*e,-2*e,e-eta1*e],-1:1,nn,nn);
C2 = spdiags([e+eta2*e,-2*e,e-eta2*e],-1:1,nn,nn);
B = spdiags([e,-2*e,e],-1:1,nn,nn);
A = (kron(speye(nn),kron(speye(nn),C1))+kron(kron(B,speye(nn))+kron(speye(nn),C2),speye(nn)))/h^2;

nn2 = nn+2;
v = 10*rand(nn2,nn2,nn2);
v2 = v;
%get b_1 from v;
b = zeros(nn,nn,nn);
%up and down
b(:,:,1) = b(:,:,1)+v(2:nn2-1,2:nn2-1,1);
b(:,:,nn) = b(:,:,nn)+v(2:nn2-1,2:nn2-1,nn2);
%left and right
b(1,:,:) = b(1,:,:)+(1+eta1)*v(1,2:nn2-1,2:nn2-1);
b(nn,:,:) = b(nn,:,:)+(1-eta1)*v(nn2,2:nn2-1,2:nn2-1);
%front and back
b(:,1,:) = b(:,1,:)+(1+eta2)*v(2:nn2-1,1,2:nn2-1);
b(:,nn,:) = b(:,nn,:)+(1-eta2)*v(2:nn2-1,nn2,2:nn2-1);

v = reshape(v(2:nn2-1,2:nn2-1,2:nn2-1),[nn^3,1]);
b = reshape(b,[nn^3,1]);
end
